package cn.gs.controller.lambdaTest;

import java.util.Arrays;
import java.util.List;

public class MethodInvokeTest {

    public static void main(String[] args) {

        List<String> list=Arrays.asList("张三","李四","王五","马六");
        list.forEach( e -> {
            int l =e.length();
            System.out.println(e);  });
        //printString
        printString01(System.out::print);
        System.out.println();
        //printInteger
        printInteger(System.out:: println);
        //printString(MethodRefObject obj)
        MethodRefObject obj= new MethodRefObject();
        printString02(obj :: printUpperCase);
        //静态方法 Math.abs
        method(-10 , n -> Math.abs(n));
        method(-10 , Math :: abs);
        //调用父类方法
        new Man().show();
        //调用本类方法
        new Husband().beHappy();
        //对象构造器
        printName("赵丽颖", name ->  new Person(name) );
        printName("刘亦菲", Person :: new);
        //数组构造器
        int[] array01 = initArray(10, length -> new int[length]) ;
        int[] array02 = initArray(11, int [] :: new);
        System.out.println(Arrays.toString(array01));
        System.out.println(Arrays.toString(array02));
    }
    //printString
    private static void printString01(Printable data){
        data.print("Hello , World !" );
    }
    //printInteger
    private static void printInteger(PrintableInteger data){
        data.printIntege(1024);
    }
    //printString(MethodRefObject obj)
    public static class MethodRefObject{
        public void printUpperCase(String str){
            System.out.println(str.toUpperCase());
        }
    }
    private static void printString02(Printable lambda){
        lambda.print("Hello");
    }
    //静态方法 Math.abs
    private static void method(int num, Calcable lambda){
        System.out.println(lambda.calc(num));
    }
    //对象构造器
    public static void printName(String name , PersonBuilder persBuild){
        System.out.println(persBuild.buildePerson(name).getName());
    }
    //数组构造器
    public static int [] initArray(int length,ArrayBuilder arraBui){
        return arraBui.arrayBuild(length);
    }
}
